//	分页区
var paginVM = new Vue({
	el : '#pagin',
	data: {
		"qo":{},
		"totalCount":0,
		"currentSize":0,
		"pageSize":0,
		"pageNo":0,
	},
	computed: {
	    startIndex: function () {
	      	return (this.pageNo - 1)*this.pageSize + 1;
	    },
	    endIndex: function () {
	      	return this.startIndex + this.currentSize - 1;
	    },
	    totalPage: function() {
	      	return Math.ceil(this.totalCount / this.pageSize);
	    },
	    showPages: function() {	//	页数太多时只显示一部份，头尾和中间三页
	    	var showPages = new Array();
	    	if(this.totalPage > 10) {
	    		showPages.push(1);
	    		if(this.pageNo - 2 > 1) {
	    			showPages.push(this.pageNo-2);
	    		}
	    		if(this.pageNo - 1 > 1) {
	    			showPages.push(this.pageNo-1);
	    		}
	    		if(this.pageNo != this.totalPage && this.pageNo != 1) {
	    			showPages.push(this.pageNo);
	    		}
	    		if(this.pageNo + 1 < this.totalPage) {
	    			showPages.push(this.pageNo+1);
	    		}
	    		if(this.pageNo + 2 < this.totalPage) {
	    			showPages.push(this.pageNo+2);
	    		}
	    		showPages.push(this.totalPage);
	    		
	    		var length = showPages.length;
	    		if(showPages[length-1] - showPages[length - 2] != 1) {
	    			var temp = showPages[length-1];
	    			showPages[length-1] = "...";
	    			showPages.push(temp);
	    		}
	    		if((showPages[1] - showPages[0]) != 1) {
	    			showPages.splice(1, 0, "...");
	    		}
	    	} else {
	    		for(var i = 1; i <= this.totalPage; i++) {
	    			showPages.push(i);
	    		}
	    	}
	    	return showPages;
	    }
	},
	methods: {
		//	更新页码
	    refresh: function (pagination) {
	    	
	    	var ps = searchVM.qo.pageSize;
	    	if(!ps){
	    		ps = 10;
	    	}
			this.totalCount = pagination.total;
			this.currentSize = pagination.size;
			this.pageSize = ps;
			this.pageNo = pagination.current;
			
	    },
	    //	点击页码
	    query: function(pageNo) {
	    	if(pageNo == 'next') {
	    		pageNo = this.pageNo + 1;
	    	} else if(pageNo == 'pre') {
	    		pageNo = this.pageNo - 1;
	    	}
	    	
	    	if(pageNo < 1 || pageNo > this.totalPage || pageNo == this.pageNo) {
	    		return false;
	    	}
	    	searchVM.qo.pageNo = pageNo;
	    	searchVM.query(0);
	    },
	    setPageSize: function() {
 			if(this.pageSize != searchVM.qo.pageSize){
 				searchVM.qo.pageSize = this.pageSize;
 				searchVM.qo.pageNo = 1;
 				searchVM.query(0);
 			}
 		}
	}
});